<?php
/**
 * Created by PhpStorm.
 * User: tjjs
 * Date: 17-5-24
 * Time: 上午11:26
 */

namespace ActionsHttp;


use Data\Consumer;
use Data\Consumer_DAO;

class ConsumerLogin extends BaseActionHttp
{
    public function doAction() {
        parent::doAction();
        // 顾客微信id
        $wx_id = $this->data[WX_ID];

        // 顾客记录
        $consumerRecord = Consumer_DAO::getRecordByWxId($wx_id);
        if (!$consumerRecord) {
            // 新顾客
            $consumerRecord = new Consumer(array());
            $consumerRecord->setWX_ID($wx_id);

            Consumer_DAO::insert($consumerRecord);
            $consumerRecord = Consumer_DAO::getRecordByWxId($wx_id);
        }

        // 老顾客
        // 存储会话
        $_SESSION[CONSUMER_ID] = $consumerRecord->getCONSUMER_ID();

        // 返回数据
        $this->ResponseDataToCurrentClient();
    }
}